﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TestPowerPoint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private UCOMIConnectionPoint m_oConnectionPoint;
        private int m_Cookie;
        private Microsoft.Office.Interop.PowerPoint.Application oPPT;


        private void button1_Click(object sender, System.EventArgs e)
        {
            // QI for IConnectionPointContainer.
            UCOMIConnectionPointContainer oConnPointContainer = (UCOMIConnectionPointContainer)oPPT;
            // Get the GUID of the EApplication interface.
            Guid guid = typeof(Microsoft.Office.Interop.PowerPoint.EApplication).GUID;

            // Find the connection point.
            oConnPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
            // Call Advise to sink up the connection.
            m_oConnectionPoint.Advise(this, out m_Cookie);
        }

        [DispId(2001)]
        public void WindowSelectionChange(Microsoft.Office.Interop.PowerPoint.Selection Sel)
        {
            this.listBox1.Items.Add("WindowSelectionChange");
        }

        [DispId(2002)]
        public void WindowBeforeRightClick(Microsoft.Office.Interop.PowerPoint.Selection Sel, bool Cancel)
        {
            this.listBox1.Items.Add("WindowBeforeRightClick");
        }

        [DispId(2003)]
        public void WindowBeforeDoubleClick(Microsoft.Office.Interop.PowerPoint.Selection Sel, bool Cancel)
        {
            this.listBox1.Items.Add("WindowBeforeDoubleClick");
        }

        [DispId(2004)]
        public void PresentationClose(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
        {
            this.listBox1.Items.Add("PresentationClose");
        }

        [DispId(2005)]
        public void PresentationSave(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
        {
            this.listBox1.Items.Add("PresentationSave");
        }

        [DispId(2006)]
        public void PresentationOpen(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
        {
            this.listBox1.Items.Add("PresentationOpen");
        }

        [DispId(2007)]
        public void NewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
        {
            this.listBox1.Items.Add("NewPresentation");
        }

        [DispId(2008)]
        public void PresentationNewSlide(Microsoft.Office.Interop.PowerPoint.Slide Sld)
        {
            this.listBox1.Items.Add("PresentationNewSlide");
        }

        [DispId(2009)]
        public void WindowActivate(Microsoft.Office.Interop.PowerPoint.Presentation Pres, Microsoft.Office.Interop.PowerPoint.DocumentWindow Wn)
        {
            this.listBox1.Items.Add("WindowActivate");
        }

        [DispId(2010)]
        public void WindowDeactivate(Microsoft.Office.Interop.PowerPoint.Presentation Pres, Microsoft.Office.Interop.PowerPoint.DocumentWindow Wn)
        {
            this.listBox1.Items.Add("WindowDeactivate");
        }

        [DispId(2011)]
        public void SlideShowBegin(Microsoft.Office.Interop.PowerPoint.SlideShowWindow Wn)
        {
            this.listBox1.Items.Add("SlideShowBegin");
        }

        [DispId(2012)]
        public void SlideShowNextBuild(Microsoft.Office.Interop.PowerPoint.SlideShowWindow Wn)
        {
            this.listBox1.Items.Add("SlideShowNextBuild");
        }

        [DispId(2013)]
        public void SlideShowNextSlide(Microsoft.Office.Interop.PowerPoint.SlideShowWindow Wn)
        {
            this.listBox1.Items.Add("SlideShowNextSlide");
        }

        [DispId(2014)]
        public void SlideShowEnd(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
        {
            this.listBox1.Items.Add("SlideShowEnd");
        }

        [DispId(2015)]
        public void PresentationPrint(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
        {
            this.listBox1.Items.Add("PresentationPrint");
        }

        [DispId(2016)]
        public void SlideSelectionChanged(Microsoft.Office.Interop.PowerPoint.SlideRange SldRange)
        {
            this.listBox1.Items.Add("SlideSelectionChanged");
        }

        [DispId(2017)]
        public void ColorSchemeChanged(Microsoft.Office.Interop.PowerPoint.SlideRange SldRange)
        {
            this.listBox1.Items.Add("ColorSchemeChanged");
        }

        [DispId(2018)]
        public void PresentationBeforeSave(Microsoft.Office.Interop.PowerPoint.Presentation Pres, bool Cancel)
        {
            this.listBox1.Items.Add("PresentationBeforeSave");
        }

        [DispId(2019)]
        public void SlideShowNextClick(Microsoft.Office.Interop.PowerPoint.SlideShowWindow Wn, Microsoft.Office.Interop.PowerPoint.Effect nEffect)
        {
            this.listBox1.Items.Add("SlideShowNextClick");
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            m_oConnectionPoint.Unadvise(m_Cookie);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oPPT);
            GC.Collect();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //Create an instance of PowerPoint.
            oPPT = new Microsoft.Office.Interop.PowerPoint.Application();


            // Show PowerPoint to the user.
            oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

        }
    }
}
